home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / x / xview / xview3.004 / xview3 / usr / openwin / include / xview_private / es.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-29  |  5.9 KB  |  193 lines

  1. /*    @(#)es.h 20.17 93/06/28 SMI    */
  2.  
  3. /*
  4.  *    (c) Copyright 1989 Sun Microsystems, Inc. Sun design patents 
  5.  *    pending in the U.S. and foreign countries. See LEGAL NOTICE 
  6.  *    file for terms of the license.
  7.  */
  8.  
  9. #ifndef _entity_stream_h_already_defined
  10. #define _entity_stream_h_already_defined
  11.  
  12. #include <xview_private/i18n_impl.h>
  13. #                    ifndef sunwindow_attr_DEFINED
  14. #include <xview/attrol.h>
  15. #                    endif
  16.  
  17. /*
  18.  * This file defines the programmer interface to the entity stream abstraction.
  19.  */
  20.  
  21. typedef struct es_object {
  22.     struct es_ops    *ops;
  23.     caddr_t         data;
  24. } Es_object;
  25. typedef struct es_object *Es_handle;
  26. #define ES_NULL        ((Es_handle)0)
  27.  
  28. typedef long int    Es_index;
  29. #define ES_CANNOT_SET    ((Es_index)0x80000000)
  30. #define ES_INFINITY    ((Es_index)0x77777777)
  31.  
  32. typedef long int    Es_status;
  33. #define    ES_SUCCESS        ((Es_status)0x0)
  34. #define    ES_CHECK_ERRNO        ((Es_status)0x1)
  35. #define    ES_CHECK_FERROR        ((Es_status)0x2)
  36. #define    ES_FLUSH_FAILED        ((Es_status)0x3)
  37. #define    ES_FSYNC_FAILED        ((Es_status)0x4)
  38. #define    ES_INVALID_ARGUMENTS    ((Es_status)0x5)
  39. #define    ES_INVALID_ATTRIBUTE    ((Es_status)0x6)
  40. #define    ES_INVALID_ATTR_VALUE    ((Es_status)0x7)
  41. #define    ES_INVALID_HANDLE    ((Es_status)0x8)
  42. #define    ES_INVALID_TYPE        ((Es_status)0x9)
  43. #define    ES_REPLACE_DIVERTED    ((Es_status)0xa)
  44. #define    ES_SEEK_FAILED        ((Es_status)0xb)
  45. #define    ES_SHORT_WRITE        ((Es_status)0xc)
  46. #define    ES_INCONSISTENT_LENGTH    ((Es_status)0xd)
  47. #define    ES_INCONSISTENT_POS    ((Es_status)0xe)
  48. #define    ES_BASE_STATUS(formal)    (formal & 0xffff)
  49. #define    ES_CLIENT_STATUS(client_mask)                     \
  50.                 ((Es_status)(0x80000000|client_mask))
  51.  
  52. #define ES_ATTR(type, ordinal)    ATTR(ATTR_PKG_ENTITY, type, ordinal+200)
  53. #define    ES_ATTR_OPAQUE_2    ATTR_TYPE(ATTR_BASE_OPAQUE, 2)
  54. #define    ES_ATTR_OPAQUE_4    ATTR_TYPE(ATTR_BASE_OPAQUE, 4)
  55. typedef enum {
  56.     ES_CLIENT_DATA        = ES_ATTR(ATTR_OPAQUE,         1),
  57.     ES_FILE_MODE        = ES_ATTR(ATTR_INT,         2),
  58.     ES_PS_ORIGINAL        = ES_ATTR(ATTR_OPAQUE,         3),
  59.     ES_PS_SCRATCH_MAX_LEN    = ES_ATTR(ATTR_INT,        30),
  60.     ES_STATUS        = ES_ATTR(ATTR_INT,         4),
  61.     ES_UNDO_MARK        = ES_ATTR(ATTR_OPAQUE,         5),
  62.     ES_UNDO_NOTIFY_PAIR    = ES_ATTR(ES_ATTR_OPAQUE_2,     6),
  63.     /*es_set only */
  64.     ES_HANDLE_TO_INSERT    = ES_ATTR(ATTR_OPAQUE,        10),
  65.     ES_STATUS_PTR        = ES_ATTR(ATTR_OPAQUE,        11),
  66.     /* es_get only */
  67.     ES_HANDLE_FOR_SPAN    = ES_ATTR(ES_ATTR_OPAQUE_4,    20),
  68.     ES_HAS_EDITS        = ES_ATTR(ATTR_BOOLEAN,        21),
  69.     ES_NAME            = ES_ATTR(ATTR_STRING,        22),
  70.     ES_PS_SCRATCH        = ES_ATTR(ATTR_OPAQUE,        23),
  71.     ES_SIZE_OF_ENTITY    = ES_ATTR(ATTR_INT,        24),
  72.     ES_TYPE            = ES_ATTR(ATTR_ENUM,        25),
  73. #ifdef OW_I18N
  74.     ES_SKIPPED        = ES_ATTR(ATTR_INT,        26),
  75. #endif
  76. } Es_attribute;
  77.  
  78. struct es_ops {
  79.   Es_status    (*commit)();
  80.   Es_handle    (*destroy)();
  81. #ifdef __STDC__
  82.   caddr_t    (*get)( Es_handle, Es_attribute, ... );
  83. #else
  84.   caddr_t       (*get)();
  85. #endif
  86.   Es_index    (*get_length)();
  87.   Es_index    (*get_position)();
  88.   Es_index    (*set_position)();
  89.   Es_index    (*read)();
  90.   Es_index    (*replace)();
  91.   int        (*set)();
  92. };
  93. typedef struct es_ops    *Es_ops;
  94.  
  95. #define es_commit(esh)                            \
  96.     (*(esh)->ops->commit)(esh)
  97. #define es_destroy(esh)                            \
  98.     (*(esh)->ops->destroy)(esh)
  99. #define es_get(esh, attr)                        \
  100.     (*(esh)->ops->get)(esh, attr)
  101. #define es_get5(esh, attr, d1, d2, d3, d4, d5)                \
  102.     (*(esh)->ops->get)(esh, attr, d1, d2, d3, d4, d5)
  103. #define es_get_length(esh)                        \
  104.     (*(esh)->ops->get_length)(esh)
  105. #define es_get_position(esh)                        \
  106.     (*(esh)->ops->get_position)(esh)
  107. #define es_set_position(esh, pos)                    \
  108.     (*(esh)->ops->set_position)((esh), (pos))
  109. #define es_read(esh, count, buf, count_read)                \
  110.     (*(esh)->ops->read)((esh), (count), (buf), (count_read))
  111. #define es_replace(esh, last_plus_one, count, buf, count_used)        \
  112.     (*(esh)->ops->replace)(                        \
  113.       (esh), (last_plus_one), (count), (buf), (count_used))
  114. /* VARARGS */
  115. EXTERN_FUNCTION( int es_set, (Es_handle esh, DOTDOTDOT ));
  116.  
  117. /*      ES_STATUS accesses the entity_stream equivalent of errno, but this
  118.  *    status is per instance, not global.  Caller must explicitly clear.
  119.  *      ES_STATUS_PTR allows calls to es_set to return a status by
  120.  *    side-effect.
  121.  *      ES_NAME returns a pointer to a statically allocated char[] and this
  122.  *    return value should be treated as read-only and volatile.
  123.  *      ES_TYPE returns a value of type Es_enum.
  124.  */
  125.  
  126. typedef enum {
  127.     ES_TYPE_MEMORY,
  128.     ES_TYPE_FILE,
  129.     ES_TYPE_PIECE,
  130.     ES_TYPE_OTHER
  131. } Es_enum;
  132.  
  133. #define    ES_NULL_UNDO_MARK    ((caddr_t)0)
  134.  
  135. #define READ_AT_EOF(before, after, read)                \
  136.     (((read) == 0) && ((before) == (after)))
  137.  
  138. /*
  139.  * Sun Microsystems supported entity streams:
  140.  *
  141.  *   Es_handle
  142.  *   es_mem_create(max, init)
  143.  *       u_int    max;
  144.  *       char   *init;
  145.  * max is the maximum number of characters the stream can ever contain.
  146.  * init is an initial value for the characters of the stream.
  147.  *
  148.  *   Es_handle
  149.  *   es_file_create(name, options)
  150.  *       char    *name;
  151.  *       int     options;
  152.  * name is the path name of the file underlying the stream.
  153.  * options is a bit-mask using the options defined below.
  154.  */
  155. #define ES_OPT_APPEND        0x00000001
  156. #define ES_OPT_OVERWRITE    0x00000002
  157. #ifdef OW_I18N
  158. #define ES_OPT_BACKUPFILE    0x00000004
  159. #endif
  160. /*
  161.  *   Es_handle
  162.  *   ps_create(client_data, original, scratch)
  163.  *    caddr_t        client_data;
  164.  *       Es_handle    original, scratch;
  165.  * original stream can (and should) be read-only.
  166.  * scratch stream has full access, and contains all edits.
  167.  */
  168.  
  169.  
  170. /* Some useful data structures and utilities for use with entity streams. */
  171.  
  172.     /* The following struct is used to pass a buffer filled by an entity
  173.      *   stream (and enough data to enable refilling it).  This is simply
  174.      *   an efficiency detail to avoid unnecessary re-reading of entities.
  175.      */
  176. typedef struct es_buf_object {
  177.     Es_handle    esh;
  178.     CHAR           *buf;
  179.     int        sizeof_buf;    /* In entities, not bytes */
  180.     Es_index    first;        /* Corresponds to buf[0] */
  181.     Es_index    last_plus_one;
  182. } Es_buf_object;
  183. typedef Es_buf_object *Es_buf_handle;
  184.  
  185. EXTERN_FUNCTION( caddr_t es_file_get, (Es_handle esh, Es_attribute attribute, DOTDOTDOT ));
  186. EXTERN_FUNCTION( caddr_t es_mem_get, (Es_handle esh, Es_attribute attribute, DOTDOTDOT ));
  187.  
  188. #define ES_READ_BUF_LEN 2047
  189. #define ES_WRITE_BUF_LEN 2047
  190.  
  191. #endif
  192.  
  193.